home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / FWExcLib / Include / FWAutoDe.h next >
Encoding:
C/C++ Source or Header  |  1994-04-21  |  3.2 KB  |  100 lines  |  [TEXT/MPS ]

  1. #ifndef FWAUTODE_H
  2. #define FWAUTODE_H
  3. //========================================================================================
  4. //
  5. //    File:                FWAutoDe.h
  6. //    Release Version:    $ 1.0d1 $
  7. //
  8. //    Creation Date:        3/28/94
  9. //
  10. //    Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  11. //
  12. //========================================================================================
  13.  
  14. #include <stddef.h>
  15.  
  16. #ifndef FWSEXCEP_H
  17. #include "FWSExcep.h"
  18. #endif
  19.  
  20. //========================================================================================
  21. //    Forward Declarations
  22. //========================================================================================
  23.  
  24. #define FW_USE_NEW_HELPER
  25.  
  26. #ifdef FW_USE_NEW_HELPER    
  27. class _FW_CPrivNewHelper;
  28. #endif
  29.  
  30. //========================================================================================
  31. // CLASS _FW_CAutoDestructObject
  32. //
  33. //    Every stack based object that must be destructed when the stack is unwound must have
  34. //    a virtual destructor as the first item in its vtbl.  This root class ensures that 
  35. //    is the case.
  36. //========================================================================================
  37.  
  38. class _FW_CAutoDestructObject
  39. {
  40.  
  41. public:
  42.  
  43.     virtual ~_FW_CAutoDestructObject();
  44.         // Virtual destructor.  Does nothing other than reserve vtbl slot.
  45.  
  46. #ifdef FW_USE_NEW_HELPER    
  47.     void* operator new(size_t size, void* p);
  48.     void* operator new(size_t size, const _FW_CPrivNewHelper &helper);
  49.     void operator delete(void *object);
  50. #endif
  51.  
  52.     // this class needs to allocate memory in its operators new and delete.  But
  53.     // without knowing about higher-level components, how can it do this using
  54.     // the application's heap manager?  Well, you must use the next two methods to
  55.     // set memory management hooks which then will be used to in new and delete
  56.     static void SetOperatorNewHandler(__FW_OperatorNewHandler operatorNewHandler);
  57.     static void SetOperatorDeleteHandler(__FW_OperatorDeleteHandler operatorDeleteHandler);
  58.  
  59.     static __FW_OperatorNewHandler GetOperatorNewHandler();
  60.     static __FW_OperatorDeleteHandler GetOperatorDeleteHandler();
  61.  
  62. public: // Internal Method
  63.  
  64.     void __Delete();
  65.         // Calls virtual destructor.  To be used only by BEL.
  66.  
  67. private:
  68. #ifdef FW_USE_NEW_HELPER    
  69.     void* operator new(size_t size) { return NULL; };
  70. #endif
  71. };
  72.  
  73. #ifndef __BORLANDC__
  74. //========================================================================================
  75. // CLASS _FW_CAutoDestructObject inline functions
  76. //========================================================================================
  77.  
  78. //----------------------------------------------------------------------------------------
  79. // _FW_CAutoDestructObject::__Delete
  80. //----------------------------------------------------------------------------------------
  81. inline void _FW_CAutoDestructObject::__Delete()
  82. {
  83. #ifdef _MPWCFRONT
  84.     // CFront is bizarre.  It won't allow the unscoped destructor name, but the scoped 
  85.     // name is dispatched virtually, even though ARM says scoped names are never virtual.
  86.     this->_FW_CAutoDestructObject::~_FW_CAutoDestructObject();
  87. #else
  88.     this->~_FW_CAutoDestructObject();    // Virtual dispatch to object's destructor
  89. #endif
  90. }
  91. #endif
  92.  
  93. inline void* _FW_CAutoDestructObject::operator new(size_t size, void* p)
  94. {
  95.     return p;
  96. }
  97.  
  98.  
  99. #endif
  100.